package cn.ekuma.epos.datalogic.define.dao;

import com.openbravo.bean.Attribute;
import com.openbravo.bean.AttributeInstance;
import com.openbravo.bean.AttributeSetInstance;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;
import cn.ekuma.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.db.table.I_AttributeInstance;

public class AttributeInstanceDAO extends ModifiedLogDAO<AttributeInstance>{

	public AttributeInstanceDAO(I_Session s) {
		super(s);
	}

	@Override
	public TableDefinition getTable() {
		return new TableDefinition(s,
                "ATTRIBUTEINSTANCE",
                new Field[]{
                   new Field(I_AttributeInstance.ID,Datas.STRING, Formats.STRING),
                   new Field(I_AttributeInstance.ATTRIBUTESETINSTANCE_ID,Datas.STRING, Formats.STRING,AttributeSetInstance.class),
                   new Field(I_AttributeInstance.ATTRIBUTE_ID,Datas.STRING, Formats.STRING,Attribute.class),
                   new Field(I_AttributeInstance.VALUE,Datas.STRING, Formats.STRING),
                   new Field(I_AttributeInstance.LASTMODIFIED,Datas.TIMESTAMP, Formats.TIMESTAMP)
                 },
                new int[]{0}
                );
	}

	@Override
	public void writeInsertValues(DataWrite dp, AttributeInstance obj)
			throws BasicException {
		dp.setString(1,obj.getId());
		dp.setString(2,obj.getAttributeSetInstanceID());
		dp.setString(3,obj.getAttributeID());
		dp.setString(4, obj.getValue());
		dp.setTimestamp(5,obj.getLastModified());
		
	}

	@Override
	public Class getSuportClass() {
		return AttributeInstance.class;
	}

	@Override
	public AttributeInstance readValues(DataRead dr, AttributeInstance obj)
			throws BasicException {
		if(obj==null)
			obj=new AttributeInstance();
		obj.setId(dr.getString(1));
		obj.setAttributeSetInstanceID(dr.getString(2));
		obj.setAttributeID(dr.getString(3));
		obj.setValue(dr.getString(4));
		obj.setLastModified(dr.getTimestamp(5));
		return obj;
	}
}
